package com.qf;

import com.qf.bean.Goods;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;

/**
 * projectName: MyBatis_1
 *
 * @author: MaTianWei
 * time: 2021/6/24 21:10
 * description:更新
 */

public class Update {
    public static void main(String[] args) throws IOException {
        //1·读取配置
        InputStream stream = Resources.getResourceAsStream("mybatis_config.xml");
        //2·创建sqlSessionFactoryBuilder
        SqlSessionFactoryBuilder factoryBuilder = new SqlSessionFactoryBuilder();
        //3·创建sqlSessionFactory
        SqlSessionFactory sqlSessionFactory = factoryBuilder.build(stream);
        //4·创建sqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //5·调用插入数据方法
        Goods goods = new Goods();
        goods.setId(21);
        goods.setName("大米10pro");
        int rows = sqlSession.insert("x.x.x.updateGoods",goods);
        if(rows>0){
            System.out.println("更新数据成功");
        }
        System.out.println(goods);
        //6·关闭资源
        sqlSession.commit();//提交事务 不提交没有数据
        sqlSession.close();
    }
}
